% $Header: c:\RCSdir\kernel/spotfunc.ps 1.11 1995/10/06 17:45:27 Mike Exp $

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% spotfunc.ps
%
% This file contains a set of spot function procedure definitions.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% freq ang Spot1 setscreen
%
% Author:	Artworks developers
% Created:	-
% Inputs:	x,y position (-1<=x,y<=1)
% Outputs:	value (between 0..1)
% Comments:
%
% Spot1 if abs(y)+abs(x)>1
%       then = (x-1)^2+(y-1)^2 -1
%		else = 1-(x^2+y^2)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

/Spot1 
{
	abs exch abs 2 copy add 1 gt
	{
		1 sub dup mul exch 
		1 sub dup mul add 
		1
	}
	{
		dup mul exch 
		dup mul add 1 
		exch
	} ifelse
	sub
} bd


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Spot2   = 1-(x^2+y^2)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

/Spot2 
{
	dup mul exch 
	dup mul add 1 
	exch sub 
	0 1 clamp
} bd


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% TripleSpot1
%
%	 a = 2*[(3*(y+1)/2)-floor(3*(y+1)/2)]-1
%	 b = 2*[(3*(x+1)/2)-floor(3*(x+1)/2)]-1
%	 if abs(a)+abs(b)>1
%    then = (a-1)^2+(b-1)^2 -1
%	 else = 1-(a^2+b^2)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

/TripleSpot1 
{
	2 
	{
		1 add 2 div 3 mul dup 
		floor sub 2 mul 1 sub 
		exch
	} repeat

	abs exch abs 2 copy add 1 

	gt
	{
		1 sub dup mul 
		exch 
		1 sub dup mul add 
		1
	}
	{
		dup mul exch 
		dup mul add 1 
		exch
	} ifelse
	sub
} def

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% TripleSpot2
%
%	 a = 2*[(3*(y+1)/2)-floor(3*(y+1)/2)]-1
%	 b = 2*[(3*(x+1)/2)-floor(3*(x+1)/2)]-1
%	 = 1-(a^2+b^2)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

/TripleSpot2
{ 
	2 
	{
		1 add 2 div 3 mul dup floor 
		sub 2 mul 1 sub 
		exch
	} repeat
	dup mul exch 
	dup mul add 1 
	exch sub
} def


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% EllipticalSpot = 1-sqrt(5/8*y^2+x^2)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

/EllipticalSpot 
{
	dup 5 mul 8 div 
	mul exch dup mul 
	exch add sqrt 
	1 exch sub 
} def


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Line = x^2
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

/Line 
{ 
	pop dup mul 
} def


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Square = if (x^2<y^2) 
%		   then = x^2
%		   else = y^2
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

/Square 
{ 
	dup mul exch 
	dup mul 
	2 copy 
	gt {exch} if 
	pop 
} bd


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Crosshatch = if (x^2<y^2) 
%			   then = y^2
%		       else = x^2
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

/Crosshatch 
{
	dup mul exch 
	dup mul 
	2 copy 
	lt {exch} if 
	pop 
	0 1 clamp
} bd


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Mezzotint = random(0..1)-1  ie = random(-1..0)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

/Mezzotint 
{ 
	pop pop 
	rand 
	16#3FFFFFFF div 
	1 sub
} bd


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Dither   a = (16*int((x+1)*7.999)
%		   b = int(y+1)*7.999
%          c = dither[a+b] / 255
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

/Dither
{
	1 add 7.9999 mul cvi                        %(y+1)*7.9999 = 0..15
	exch
	1 add 7.9999 mul cvi                        %(x+1)*7.9999 = 0..15
	16 mul add
    <0E 8E 2E AE 06 86 26 A6 0C 8C 2C AC 04 84 24 A4
     CE 4E EE 6E C6 46 E6 66 CC 4C EC 6C C4 44 E4 64
     3E BE 1E 9E 36 B6 16 96 3C BC 1C 9C 34 B4 14 94
     FE 7E DE 5E F6 76 D6 56 FC 7C DC 5C F4 74 D4 54
     01 81 21 A1 09 89 29 A9 03 83 23 A3 0B 8B 2B AB
     C1 41 E1 61 C9 49 E9 69 C3 43 E3 63 CB 4B EB 6B
     31 B1 11 91 39 B9 19 99 33 B3 13 93 3B BB 1B 9B
     F1 71 D1 51 F9 79 D9 59 F3 73 D3 53 FB 7B DB 5B
     0D 8D 2D AD 05 85 25 A5 0F 8F 2F AF 07 87 27 A7
     CD 4D ED 6D C5 45 E5 65 CF 4F EF 6F C7 47 E7 67
     3D BD 1D 9D 35 B5 15 95 3F BF 1F 9F 37 B7 17 97
     FD 7D DD 5D F5 75 D5 55 FF 7F DF 5F F7 77 D7 57
     02 82 22 A2 0A 8A 2A AA 00 80 20 A0 08 88 28 A8
     C2 42 E2 62 CA 4A EA 6A C0 40 E0 60 C8 48 E8 68
     32 B2 12 92 3A BA 1A 9A 30 B0 10 90 38 B8 18 98
     F2 72 D2 52 FA 7A DA 5A F0 70 D0 50 F8 78 D8 58 
	>
    exch get 255 div
} bd

